

package com.nn.smart.bus.controller;

import com.nn.smart.bus.commons.tools.page.PageData;
import com.nn.smart.bus.commons.tools.utils.ExcelUtils;
import com.nn.smart.bus.commons.tools.utils.Result;
import com.nn.smart.bus.commons.tools.validator.AssertUtils;
import com.nn.smart.bus.commons.tools.validator.ValidatorUtils;
import com.nn.smart.bus.commons.tools.validator.group.AddGroup;
import com.nn.smart.bus.commons.tools.validator.group.UpdateGroup;
import com.nn.smart.bus.commons.tools.validator.group.DefaultGroup;
import com.nn.smart.bus.dto.NnclNnrouteStationRelationDTO;
import com.nn.smart.bus.excel.NnclNnrouteStationRelationExcel;
import com.nn.smart.bus.service.NnclNnrouteStationRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


/**
 * 公交线路站点关系表 
 *
 * @author nanning nanning@123.com
 * @since v1.0.0 2021-08-25
 */
@RestController
@RequestMapping("nnclnnroutestationrelation")
public class NnclNnrouteStationRelationController {

    @Autowired
    private NnclNnrouteStationRelationService nnclNnrouteStationRelationService;

    @GetMapping("page")
    public Result<PageData<NnclNnrouteStationRelationDTO>> page(@RequestParam Map<String, Object> params){
        PageData<NnclNnrouteStationRelationDTO> page = nnclNnrouteStationRelationService.page(params);
        return new Result<PageData<NnclNnrouteStationRelationDTO>>().ok(page);
    }

    @GetMapping("{id}")
    public Result<NnclNnrouteStationRelationDTO> get(@PathVariable("id") String id){
        NnclNnrouteStationRelationDTO data = nnclNnrouteStationRelationService.get(id);
        return new Result<NnclNnrouteStationRelationDTO>().ok(data);
    }

    @PostMapping
    public Result save(@RequestBody NnclNnrouteStationRelationDTO dto){
        //效验数据
        ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
        nnclNnrouteStationRelationService.save(dto);
        return new Result();
    }

    @PutMapping
    public Result update(@RequestBody NnclNnrouteStationRelationDTO dto){
        //效验数据
        ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
        nnclNnrouteStationRelationService.update(dto);
        return new Result();
    }

    @DeleteMapping
    public Result delete(@RequestBody String[] ids){
        //效验数据
        AssertUtils.isArrayEmpty(ids, "id");
        nnclNnrouteStationRelationService.delete(ids);
        return new Result();
    }

    @GetMapping("export")
    public void export(@RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
        List<NnclNnrouteStationRelationDTO> list = nnclNnrouteStationRelationService.list(params);
        ExcelUtils.exportExcelToTarget(response, null, list, NnclNnrouteStationRelationExcel.class);
    }

}
